<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAppSourcesTable extends Migration
{
    private const TABLE = 'app_sources';

    public function up()
    {
        if (Schema::connection('gameCenter')->hasTable(self::TABLE)) {
            return ;
        }
        Schema::connection('gameCenter')->create(self::TABLE, function (Blueprint $table) {
            $table->id();
            $table->string('name')->default('')->comment('名称');
            $table->string('desc')->default('')->comment('说明');
            $table->unsignedTinyInteger('type')->default(0)->comment('渠道类型');
            $table->unsignedTinyInteger('os')->default(0)->comment('系统类型 0:安卓 1:ios');
            $table->unsignedTinyInteger('status')->default(0)->comment('状态')->index();
            $table->unsignedTinyInteger('register')->default(1)->comment('开启注册')->index();
            $table->unsignedTinyInteger('audit')->default(0)->comment('开启审核')->index();
            $table->unsignedInteger('app_source_config_id')->default(0)->comment('渠道方案ID');
            $table->timestamps();

            $table->index(['status', 'type']);
        });
        DB::connection('gameCenter')->statement("ALTER TABLE `tb_".self::TABLE."` comment '渠道配置'");
    }

    public function down()
    {
        Schema::connection('gameCenter')->dropIfExists(self::TABLE);
    }
}
